package com.game.majiang.vo;

import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;


public class GameLogVo {

	int roomNumber;
	int gamechang;
	int userid;
	int score;//分数
	String playback;
	int type;
	
	public void insertGameLog()
	{
		String cmdText = "insert into gamelog(roomNumber,gamechang,userid,score,playtype)values(?,?,?,?,?)";
		Parameter p1 = new Parameter(Types.INTEGER, roomNumber, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, gamechang, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, userid, ParameterType.Input);
		Parameter p4 = new Parameter(Types.INTEGER, score, ParameterType.Input);
		Parameter p5 = new Parameter(Types.INTEGER, type, ParameterType.Input);
		SqlHelperwrite.execute(cmdText,p1,p2,p3,p4,p5);
	}
	
	
	public static void insertchexuanpilog(int pi)
	{
		String cmdText = "insert into chexuanpilog(shengyupi)values(?)";
		//Parameter p1 = new Parameter(Types.INTEGER, tableid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, pi, ParameterType.Input);
		
		SqlHelperwrite.execute(cmdText,p2);
	}
//	public static List<zhanjiInfo> sekectGameLog(int id)
//	{
//		List<zhanjiInfo>  list = new ArrayList<zhanjiInfo>();
//		String cmdText = "select id,roomNumber,score,playtype,creattime from gamelog where userid=? group by id desc ";
//		Parameter p1 = new Parameter(Types.INTEGER, id, ParameterType.Input);
//		CachedRowSet rs = SqlHelper.getResultSet(cmdText, p1);
//		try {
//			while (rs.next()) 
//			{
//				zhanjiInfo z = new zhanjiInfo();
//				z.setId(rs.getInt(1));
//				z.setRoomid(rs.getInt(2));
////				z.setSocre(rs.getInt(3));
//				z.setType(rs.getInt(4));
//				z.setTime(rs.getString(5));
//				list.add(z);
//			}
//		} catch (SQLException e) {
//			e.printStackTrace();
//			log.warn("Sql:" + cmdText + "错误!");
//		}
//		return list;
//	}
	public static String sekectplayback(int id)
	{
		
		String cmdText = "select playback from gamelog where id=?  ";
		Parameter p1 = new Parameter(Types.INTEGER, id, ParameterType.Input);
		Object obj=SqlHelper.execScalar(cmdText, p1);
		
		return (String)obj;
		
		
	}
	
	
	/**
	 * 查一天胜场
	 */
	public int checkAFieldDay(int uid){
		
		 Date now = new Date();
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		 String str =sdf.format(now);
		 String starttime = str+" 00:00:00";
		 String endtime = str+" 23:59:59";
		 String cmdText = "SELECT COUNT(id) FROM gamelog WHERE userid=? AND creattime>?  AND creattime <=? AND score>0";
		 Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		 Parameter p2 = new Parameter(Types.INTEGER, starttime, ParameterType.Input);
		 Parameter p3 = new Parameter(Types.INTEGER, endtime, ParameterType.Input);
		 Object obj =SqlHelper.execute(cmdText, p1,p2,p3);
		Long l = (Long)obj;
		return l.intValue();
	}
	/**
	 * 查一周胜场
	 */
	public int checkAWeekOfVictory(int uid){
		//SELECT COUNT(id) FROM gamelog WHERE YEARWEEK(date_format(creattime,'%Y-%m-%d')) = YEARWEEK(now())  AND userid=128785 AND score>0
		 String cmdText = "SELECT COUNT(id) FROM gamelog WHERE YEARWEEK(date_format(creattime,'%Y-%m-%d')) = YEARWEEK(now())  AND userid=? AND score>0";
		 Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		 Object obj =SqlHelper.execute(cmdText, p1);
		 Long l = (Long)obj;
		return l.intValue();
	}
	
	public static void addgamezenglog(int zid,int sid,int zhuan)
	{
		String cmdText = "insert into gamezenglog(zid,sid,zhuan)values(?,?,?)";
		Parameter p1 = new Parameter(Types.INTEGER, zid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, sid, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, zhuan, ParameterType.Input);
		SqlHelperwrite.execute(cmdText,p1,p2,p3);
	}
	
}
